package com.club.uni.config;

import com.getui.push.v2.sdk.ApiHelper;
import com.getui.push.v2.sdk.GtApiConfiguration;
import com.getui.push.v2.sdk.api.PushApi;
import com.getui.push.v2.sdk.api.UserApi;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Component;

/**
 * @Author: wxj
 * @Date: 2021-04-23 15:31
 */
@Component
public class PInit {


    @Autowired
    private PlatformGeTuiConfig platformGeTuiConfig;

    @Bean("platformPushApi")
    public PushApi getPushApi(){
        GtApiConfiguration apiConfiguration = new GtApiConfiguration();
        //填写应用配置
        apiConfiguration.setAppId(platformGeTuiConfig.getAppId());
        apiConfiguration.setAppKey(platformGeTuiConfig.getAppKey());
        apiConfiguration.setMasterSecret(platformGeTuiConfig.getMasterSecret());
        // 接口调用前缀，请查看文档: 接口调用规范 -> 接口前缀, 可不填写appId
        apiConfiguration.setDomain("https://restapi.getui.com/v2/");
        // 实例化ApiHelper对象，用于创建接口对象
        ApiHelper apiHelper = ApiHelper.build(apiConfiguration);
        // 创建对象，建议复用。目前有PushApi、StatisticApi、UserApi
        PushApi pushApi = apiHelper.creatApi(PushApi.class);
        return  pushApi;
    }

    @Bean("platformUserApi")
    public UserApi getUserApi() {
        GtApiConfiguration apiConfiguration = new GtApiConfiguration();
        //填写应用配置
        apiConfiguration.setAppId(platformGeTuiConfig.getAppId());
        apiConfiguration.setAppKey(platformGeTuiConfig.getAppKey());
        apiConfiguration.setMasterSecret(platformGeTuiConfig.getMasterSecret());
        // 接口调用前缀，请查看文档: 接口调用规范 -> 接口前缀, 可不填写appId
        apiConfiguration.setDomain("https://restapi.getui.com/v2/");
        // 实例化ApiHelper对象，用于创建接口对象
        ApiHelper apiHelper = ApiHelper.build(apiConfiguration);
        // 创建对象，建议复用。目前有PushApi、StatisticApi、UserApi
        UserApi userApi = apiHelper.creatApi(UserApi.class);
        return  userApi;
    }


    public String pageName(){
        return platformGeTuiConfig.getPackageName();
    }
}
